/**
  ETFAna project, Anyang Normal University && IMP-CAS
  \class ETFGlobalTracker
  \brief for tracking around the reaction target with united tracking algorithm,
  making use of postMag track info and preTaTrk-postTaTrk inconsistencies
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2021-11-10
  \date 2021-11-23 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date         <th>Author      <th>Description                   </tr>
  <tr>  <td>2021-11-10   <td>Asia Sun    <td>file created                  </tr>
  </table>

  \copyright Copyright (c) 2021-2024 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#ifndef ETFGlobalTracker_h
#define ETFGlobalTracker_h

#include "ETFTaTracker.h"

class ETFVTrack;
class ETFTimer;

class ETFGlobalTracker : public ETFTaTracker{
public:
  ETFGlobalTracker(const char *name = "");
  /// t0, t1: for timing of DCTaArrU,D. Use t0 = t1 if tstop1 is empty
  ETFGlobalTracker(const char *name, const vector<string> &dcs, const string &t0,
    const string &t1 = "");
  virtual ~ETFGlobalTracker();

  using ETFTaTracker::Map;
  virtual void Map() override; ///< X tracking
  virtual void Map3D() override; ///< intended not to be used for GlobalTracker
  // replace X tracks in pre/post-TaTrackers with ameliorated global ones
  void SetPostMagTrk(double k, double b){ fK3 = k; fB3 = b; }
  void SetPostMagTrk(ETFVTrack *trk);
  virtual void UpdateTracks(ETFTaTracker *pre, ETFTaTracker *post);
  virtual void Initialize() override;
  void SetChiPD(double c0, double c1){ fChiPDv[0] = c0; fChiPDv[1] = c1; }
  void SetD2THREPD(double d0, double d1){ D2THREPDv[0] = d0; D2THREPDv[1] = d1; }

  // ClassDefOverride(ETFGlobalTracker, 1);

protected:
  /// called by Map, to test if a hit combination is eligible
  virtual bool TestCombination(TrackType type) override; ///< \param type: track type
  /// \retval false: if obtained drift time is out of range
  virtual bool SetDriftDistance(ETFVTrack *trk) override;
  virtual bool SetDriftDistance(ETFVTrack *preTaTrk, ETFVTrack *postTaTrk);

  using ETFTracker::UpdateHitPos;
  /// update the hit position of the tracks in the tracker
  virtual void UpdateHitPos() override;

  double fK3, fB3; ///< l: x=fK3*z+fB3, postMagTrk
  double fChiPDv[2]; ///< chiPD of [0:preTaTrk] and [1:postTaTrk]
  double D2THREPDv[2]; ///< D2THREPD of [0:preTaTrk] and [1:postTaTrk]
};

#endif
